﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Monitoring;
using ScrumTable.Common.Threading;
using ScrumTable.DL.Data.Common.Config.Driver;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

#endregion

namespace ScrumTable.DL.Data.Common
{
    /// <summary>
    /// Contains all data used by the data layer, this is the entry
    /// point for the data layer and contains all required objects in
    /// order to connect to a data source.
    /// </summary>
    public interface IDataContext : IDisposableObject
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the driver information provided by the ScrumTable plugin
        /// framework.
        /// </summary>
        IDataContextInfo DriverInformation { get; }

        /// <summary>
        /// Gets the associated data layer schema.
        /// </summary>
        ScrumTableV1Schema Schema { get; }

        /// <summary>
        /// Gets associated data connection.
        /// </summary>
        IDataConnection Connection { get; }

        /// <summary>
        /// Gets associated driver configuration data.
        /// </summary>
        IDriverConfig Configuration { get; }

        /// <summary>
        /// Gets data storage.
        /// </summary>
        IDataStorage Storage { get; }

        /// <summary>
        /// Gets or sets the flow control dispatcher. This sychronization
        /// dispatcher is used for the async callback handling.
        /// </summary>
        /// <remarks>
        /// This dispatcher is used to synchronize calls back into the main message queue.
        /// </remarks>
        IDataSyncDispatcher DataSyncDispatcher { get; set; }

        /// <summary>
        /// Gets a flag which indicates that value change events on the
        /// current context should be propagated to the event listeners.
        /// </summary>
        bool PropagateEvents { get; set; }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Loads all data of the current data context below the given id from the given
        /// location.
        /// </summary>
        /// <param name="idChain">The data below the given id should be imported.</param>
        /// <param name="importMonitor">Specifies the monitor which observes the import.</param>
        void ImportData(ValueChain<string> idChain, IDataImportMonitor importMonitor);

        /// <summary>
        /// Stores the data of the current data context back to the underlying system.
        /// </summary>
        /// <param name="callbackEvent">Specifies the callback which is fired after the
        /// process has been completed. The callback is of type ICancellableDataResult
        /// and its Data property contains true, if all changes have been accepted.</param>
        void ExportData(AsyncCallback callbackEvent);

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        /// <summary>
        /// Specifies that the bulk data update starts.
        /// </summary>
        event UpdateBeginEventHandler BeginUpdate;

        /// <summary>
        /// Specifies that the bulk data update ends.
        /// </summary>
        event UpdateEndEventHandler EndUpdate;

        #endregion
    }
}